class Index extends eui.Component implements eui.UIComponent {
	public constructor() {
		super();
		this.skinName = "IndexSkin";

	}

	protected partAdded(partName: string, instance: any): void {
		super.partAdded(partName, instance);
	}

	private Anite;
	private backAnite;
	private rule;
	private gamerules;
	private play;
	private Award;
	private winners;

	protected childrenCreated(): void {
		// 点击开始按钮
		this.play.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
			SceneManager.getObj(this.stage).loadScene("game", bgRun)
		}, this)

		super.childrenCreated();
		this.playAnimation(this.Anite, true);
		this.backAnite.play();
		// 点击规则按钮
		this.rule.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
			this.gamerules = new Gamerules();
			this.addChild(this.gamerules);
		}, this)
		this.addEventListener(egret.Event.ENTER_FRAME, this.OnEvent, this);

		// 点击获奖按钮
		this.Award.addEventListener(egret.TouchEvent.TOUCH_TAP, () => {
			// 判断this.winners是否被赋值，是的不操作，否则就赋值
			if (!this.winners) {
				this.winners = new Winners();
			}
			this.winners.returnfan.once(egret.TouchEvent.TOUCH_TAP,function(){
				this.removeChild(this.winners);
				this.winners = null;
			},this)
			this.addChild(this.winners);
		}, this)


	}
	/**监听事件 *///有一个就好，不用多写，用到监听的就写这里面就行
	private OnEvent(): void {
		// if (this.gamerules) {
		// 	if (this.gamerules.isopen) {
		// 		this.gamerules.isopen = false;
		// 		this.removeChild(this.gamerules);
		// 		this.gamerules = null;
		// 	}
		// }

		// 游戏规则
		if (Gamerules.isopen) {
			Gamerules.isopen = false;
			this.removeChild(this.gamerules);
			this.gamerules = null;
		}
		// 获奖名单
		// if (Winners.fanhui) {
		// 	Winners.fanhui = false;
		// 	console.log(this.winners);
		// 	if (this.contains(this.winners)) {
		// 		this.removeChild(this.winners);
		// 		// this.winners = null;
		// 	}

		// }
	}

	// private OnEventwin(){
	// 	if (Winners.fanhui) {
	// 		Winners.fanhui = false;
	// 		this.removeChild(this.winners);
	// 		this.winners = null;
	// 	}
	// }



	//设置循环播放
	private playAnimation(target: egret.tween.TweenGroup, isLoop: boolean): void {
		if (isLoop) {
			for (var key in target.items) {
				target.items[key].props = { loop: true };
			}
		}
		target.play();
	}


}